package com.irdstudio.efp.rule.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.rule.service.dao.TaxFileInfoTempDao;
import com.irdstudio.efp.rule.service.domain.TaxFileInfoTemp;
import com.irdstudio.efp.rule.service.facade.TaxFileInfoTempService;
import com.irdstudio.efp.rule.service.vo.TaxFileInfoTempVO;

/**
 * <p>ServiceImpl: 回写税局文件临时表				<p>
 * @author ligm
 * @date 2019-05-28
 */
@Service("taxFileInfoTempService")
public class TaxFileInfoTempServiceImpl implements TaxFileInfoTempService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(TaxFileInfoTempServiceImpl.class);

	@Autowired
	private TaxFileInfoTempDao taxFileInfoTempDao;
	
	/**
	 * 新增操作
	 */
	public int insertTaxFileInfoTemp(TaxFileInfoTempVO inTaxFileInfoTempVo) {
		logger.debug("当前新增数据为:"+ inTaxFileInfoTempVo.toString());
		int num = 0;
		try {
			TaxFileInfoTemp taxFileInfoTemp = new TaxFileInfoTemp();
			beanCopy(inTaxFileInfoTempVo, taxFileInfoTemp);
			num = taxFileInfoTempDao.insertTaxFileInfoTemp(taxFileInfoTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(TaxFileInfoTempVO inTaxFileInfoTempVo) {
		logger.debug("当前删除数据条件为:"+ inTaxFileInfoTempVo);
		int num = 0;
		try {
			TaxFileInfoTemp taxFileInfoTemp = new TaxFileInfoTemp();
			beanCopy(inTaxFileInfoTempVo, taxFileInfoTemp);
			num = taxFileInfoTempDao.deleteByPk(taxFileInfoTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxFileInfoTempVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(TaxFileInfoTempVO inTaxFileInfoTempVo) {
		logger.debug("当前修改数据为:"+ inTaxFileInfoTempVo.toString());
		int num = 0;
		try {
			TaxFileInfoTemp taxFileInfoTemp = new TaxFileInfoTemp();
			beanCopy(inTaxFileInfoTempVo, taxFileInfoTemp);
			num = taxFileInfoTempDao.updateByPk(taxFileInfoTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxFileInfoTempVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public TaxFileInfoTempVO queryByPk(TaxFileInfoTempVO inTaxFileInfoTempVo) {
		
		logger.debug("当前查询参数信息为:"+ inTaxFileInfoTempVo);
		try {
			TaxFileInfoTemp queryTaxFileInfoTemp = new TaxFileInfoTemp();
			beanCopy(inTaxFileInfoTempVo, queryTaxFileInfoTemp);
			TaxFileInfoTemp queryRslTaxFileInfoTemp = taxFileInfoTempDao.queryByPk(queryTaxFileInfoTemp);
			if (Objects.nonNull(queryRslTaxFileInfoTemp)) {
				TaxFileInfoTempVO outTaxFileInfoTempVo = beanCopy(queryRslTaxFileInfoTemp, new TaxFileInfoTempVO());
				logger.debug("当前查询结果为:"+ outTaxFileInfoTempVo.toString());
				return outTaxFileInfoTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<TaxFileInfoTempVO> queryAllOwner(TaxFileInfoTempVO taxFileInfoTempVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<TaxFileInfoTempVO> list = null;
		try {
			List<TaxFileInfoTemp> taxFileInfoTemps = taxFileInfoTempDao.queryAllOwnerByPage(taxFileInfoTempVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ taxFileInfoTemps.size());
			pageSet(taxFileInfoTemps, taxFileInfoTempVo);
			list = (List<TaxFileInfoTempVO>) beansCopy(taxFileInfoTemps, TaxFileInfoTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<TaxFileInfoTempVO> queryAllCurrOrg(TaxFileInfoTempVO taxFileInfoTempVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<TaxFileInfoTemp> taxFileInfoTemps = taxFileInfoTempDao.queryAllCurrOrgByPage(taxFileInfoTempVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+taxFileInfoTemps.size());
		List<TaxFileInfoTempVO> list = null;
		try {
			pageSet(taxFileInfoTemps, taxFileInfoTempVo);
			list = (List<TaxFileInfoTempVO>) beansCopy(taxFileInfoTemps, TaxFileInfoTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<TaxFileInfoTempVO> queryAllCurrDownOrg(TaxFileInfoTempVO taxFileInfoTempVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<TaxFileInfoTemp> taxFileInfoTemps = taxFileInfoTempDao.queryAllCurrDownOrgByPage(taxFileInfoTempVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ taxFileInfoTemps.size());
		List<TaxFileInfoTempVO> list = null;
		try {
			pageSet(taxFileInfoTemps, taxFileInfoTempVo);
			list = (List<TaxFileInfoTempVO>) beansCopy(taxFileInfoTemps, TaxFileInfoTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public int insertByBatch(List<TaxFileInfoTempVO> taxFileInfoTempList) {
		logger.debug("当前新增数据为:"+ taxFileInfoTempList.toString());
		int num = 0;
		try {
			num = taxFileInfoTempDao.insertByBatch(taxFileInfoTempList);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	@Override
	public void deleteAll() {
		int num = 0;
		try {
			num = taxFileInfoTempDao.deleteAll();
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("删除的数据条数为"+ num);
	}
}
